<?php
    //require section
    require_once dirname(__FILE__) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_security.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_news.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_invoice.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_document.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_buy.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_multi_level.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_statistics.php';



    $category_groups = api_document::get_all_document_categories();

    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'usable_functions.php';

    $title = 'Index';
?>


<!DOCTYPE html>
<html>
<head>
    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
    ?>
</head>
<body>
<div class="uk-container uk-container-center uk-margin-top">
    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';
    ?>

    <section id="main-content" class="ts-body-container">
        <div class="ts-left-wrapper">
            <?php
            $newses = api_news::get_all_latest_news(4);
            $category = api_news::get_news_category_by_id($newses[0]['cat_news_id']);
            if (!empty($category) && count($category) > 0) {
            ?>
            <div class="uk-panel uk-margin-bottom">
                <h3 class="ts-category-title">
                    
                    <a href="<?php echo LINK_ROOT ?>/news.php?cat_id=<?php echo $category['cat_news_id']; ?>" data-uk-tooltip
                       title="Xem tin tức thuộc <b style='color: #fff;'><?php echo $category['cate_news_name']; ?></b>">
                        <i class="uk-icon-folder-open"></i> <?php echo $category['cate_news_name']; ?>
                    </a>
                </h3>
                <div class="ts-category-content">
                    <div class="entrygroup">
                      <div class="content">
                        <h3><b><a href="<?php echo LINK_ROOT ?>/news_detail.php?news_id=<?php echo $newses[0]['news_id']; ?>"><?php echo $newses[0]['news_title']; ?></a></b></h3>
                        <div class="left-image">
                        <a href="<?php echo LINK_ROOT ?>/news_detail.php?news_id=<?php echo $newses[0]['news_id']; ?>">
                            <img class="thumb" style="padding-right:5px" src="<?php echo LINK_ROOT . DIR_SHARED_UPLOAD_IMAGES_NEWS . $newses[0]['news_img_url']; ?>" alt="<?php echo $newses[0]['news_img_url']; ?>">
                        </a>        
                        </div>
                        <div class="right-content">
                            <p>
                            <?php echo substr(strip_tags($newses[0]['news_content']), 0, 320); ?>...
                            </p>
                        </div>
                        
                     </div>
                     <div class="clear"></div>
                     <div class="relative">
                        <ul>
                            <?php 
                            for ($index = 1; $index < count($newses); $index++) {
                            ?>
                            <li>
                                <a href="<?php echo LINK_ROOT ?>/news_detail.php?news_id=<?php echo $newses[$index]['news_id']; ?>">
                                    <?php echo $newses[$index]['news_title']; ?></a></li>
                            <?php
                            }
                            ?>
                        </ul>
                     </div>
                    </div>

                </div>
            </div>
            <?php
            }
            ?>
            <?php
                if (!empty($category_groups) && count($category_groups) > 0) {
                    foreach ($category_groups as $group) {
                        show_category_group($group, 6);
                    }
                }
            ?>


        </div>
        <script type="text/javascript">
            function filldata(value) {
                $.ajax({
                    type: "GET",
                    url: "<?php echo LINK_ROOT . DIR_AJAX; ?>document_folder_category.php",
                    data: "category_choosen_id=" + value,
                    success: function (result) {
                        $("#category-list").html(result);
                    }
                });
            }
        </script>
        <div class="ts-right-wrapper">
            
            <div class="uk-panel uk-margin-bottom">
                <div class="ts-category-title"><i class="uk-icon-list-ul"></i> Danh mục bài tập</div>
                <ul id="category-list" class="ts-category-list">
                    <!-- ajax loading -->
                    <?php
                        show_root_list();
                    ?>
                </ul>
            </div>

            <div class="uk-panel uk-margin-bottom">
                <div class="ts-category-title"><i class="uk-icon-users"></i> Thống kê truy cập</div>
                <div class="ts-category-content">Tổng số lượt truy cập:
                    <b><?php echo api_statistics::get_access_number(); ?></b></div>
            </div>
        </div>
    </section>

    <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
    ?>
</div>
</body>
</html>